/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.wisnu.example.database;

import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;
import com.wisnu.example.service.PtikDao;
import com.wisnu.example.service.impl.PtikDaoImpl;
import java.sql.Connection;
import java.sql.SQLException;

/**
 *
 * @author Wisnu Wardoyo
 */
public class Database {

    private static Connection connection;

    private static PtikDao ptikDao;

    public static Connection getConnection() throws SQLException {
        if (connection == null) {
            MysqlDataSource dataSource = new MysqlDataSource();
            dataSource.setURL("jdbc:mysql://localhost:3306/example");
            dataSource.setUser("root");
            dataSource.setPassword("");

            connection = dataSource.getConnection();
        }
        return connection;
    }

    public static PtikDao getPtikDao() throws SQLException {
        if (ptikDao == null) {
            ptikDao = new PtikDaoImpl(getConnection());
        }
        return ptikDao;
    }

}
